import { put } from "./request";

// 服务器地址
export const serverUrl = "http://localhost:5173";

/**
 * 处理资源路径
 * @param {*} url
 * @returns
 */
export const dalImg = (url) => {
  if (url) {
    if (url.startsWith("http")) {
      return url;
    }
    return url;
  } else {
    return "https://img0.baidu.com/it/u=2556283513,3314307180&fm=253&fmt=auto&app=138&f=JPEG?w=514&h=500";
  }
};

//登录
export let setToken = (token) => {
  sessionStorage.setItem("token", token);
};

export let getToken = () => sessionStorage.getItem("token");
export let removeToken = () => sessionStorage.removeItem("token");
export let isLoginEd = () => (getToken() ? true : false);

//处理本地图片
export let getImg = (path, data) => {
  return `src/${path}/image/${data}.png`;
};

//处理富文本
export let dalHtml = (str) => {
  if (str.startsWith("<p>")) {
    return str.substring(3);
  } else {
    return str;
  }
};
